﻿using System;
using VQWEB.common;

namespace VQWEB.huongnghiep.BL
{
    public class Ulties
    {
        public static int GetRequestId(string surl, string startChar, string endChar)
        {
            int iStart = surl.LastIndexOf(startChar, System.StringComparison.Ordinal);
            int iEnd = surl.LastIndexOf(endChar, System.StringComparison.Ordinal);
            if (iEnd - iStart > 0)
            {
                int iLength = iEnd - iStart - 1;
                if (IsNumeric(surl.Substring(iStart + 1, iLength)))
                {
                    return Convert.ToInt32(surl.Substring(iStart + 1, iLength));
                }
                else
                {
                    return -1;
                }
            }
            else
            {
                return -1;
            }
        }
        public static System.Boolean IsNumeric(System.Object Expression)
        {
            if (Expression == null || Expression is DateTime)
                return false;

            if (Expression is Int16 || Expression is Int32 || Expression is Int64 || Expression is Decimal || Expression is Single || Expression is Double || Expression is Boolean)
                return true;

            try
            {
                if (Expression is string)
                    Double.Parse(Expression as string);
                else
                    Double.Parse(Expression.ToString());
                return true;
            }
            catch
            {
            } // just dismiss errors but return false
            return false;
        }
        public  static string FormatNewsUrl(int? categoryid, string categoryname, int newsid, string title)
        {
            if (categoryid == null) categoryid = -1;
            if (categoryname == null) categoryname = "Tin tuc";
            return string.Format(Const.news_Url_Template, Unit.ConvertToUnSign(categoryname).ToLower(), Unit.ConvertToUnSign(title).ToLower() + "-c" + categoryid.ToString() + "i" + newsid.ToString());
        }
        public static string FormatNewsCategoryUrl(int? categoryid, string categoryname)
        {
            if (categoryid == null) categoryid = -1;
            if (categoryname == null) categoryname = "Tin tuc";

            return string.Format(Const.news_Category_Url_Template, Unit.ConvertToUnSign(categoryname).ToLower() + "-" + categoryid.ToString());
        }
        public static string FormatChuyenNganhUrl(int? chuyennganhid, string chuyennganhname)
        {
            return string.Format(Const.chuyennganh_Url_Template, Unit.ConvertToUnSign(chuyennganhname).ToLower() + "-" + chuyennganhid.ToString());
        }
        public static string FormatTruongUrl(int? truongid, string truongname)
        {
            return string.Format(Const.truong_Url_Template, Unit.ConvertToUnSign(truongname).ToLower() + "-" + truongid.ToString());
        }
        public static string FormatDoanhNghiepUrl(int? doanhnghiepid, string doanhnghiepname)
        {
            return string.Format(Const.doanhnghiep_Url_Template, Unit.ConvertToUnSign(doanhnghiepname).ToLower() + "-" + doanhnghiepid.ToString());
        }
    }
}